home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 22 / macformat_22.iso / Shareware / Programación / enteract-377 / enteract-377.sit / EnterAct Stuff / write your own Drag_on / CodeResource_Files.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-22  |  4.0 KB  |  3 lines  |  [TEXT/KEEN]

  1. CodeResource_Files.cTEXTKEEN ò´˜Z´˜ZÅÅ=–/* CodeResource_Files.c - read stdin, write stdoutusing Mac calls rather than stdio. *//* stdin and stdout are just ordinary text files, the full pathnames for these files being supplied by the calling applicationin gacc.stdInFileName and gacc.stdOutFileName - gacc is a globalcopy of the AppCodeComm struct passed to the code resource by theapplication (see Code_Main.c). The full path name is converted toa regular file name and vRefNum, and then things proceed in a verystandard way, like reading or saving using SFGetFile or SFPutFile.*/#include "CodeResource.h"#include "AppCodeComm.h"#include <string.h>Handle ReadStdIn(void);Boolean PutToStdOut(Handle hText);short GetNameAndVRefNum(char *name, char *filename);/* Read in the contents of stdin to a handle. Note if there isnothing in the file then NULL is returned rather than an emptyhandle. The full path name of stdin is in gacc.stdInFileName. */Handle ReadStdIn()    {    Handle        hText = NULL;    long        count;    short            saveVol, refNum, vRefNum;    char        filename[32];    Boolean        opened = FALSE;        if (GetVol(NULL, &saveVol))        saveVol = 0;    if ((vRefNum = GetNameAndVRefNum(gacc.stdInFileName, filename)) == 0)        goto JumpOut;        if (FSOpen((StringPtr)filename, vRefNum, &refNum))        goto JumpOut;    else        opened = TRUE;    if (GetEOF(refNum, &count) || count <= 0L)        goto JumpOut;    hText = NewHandle(count);    if (MemError() != noErr)        {        MemoryAlert();        goto JumpOut;        }    if (FSRead(refNum, &count, *hText))        {        DisposHandle(hText);        hText = NULL;        goto JumpOut;        }JumpOut:    if (opened)        FSClose(refNum);    if (saveVol)        SetVol(NULL, saveVol);    return(hText);    }/* Write the text in hText to stdout as specified by the full path namein gacc.stdOutFileName. */Boolean PutToStdOut(Handle hText)    {    long        count;    short            saveVol, refNum, vRefNum;    char        filename[32];        if (GetVol(NULL, &saveVol))        saveVol = 0;    if ((vRefNum = GetNameAndVRefNum(gacc.stdOutFileName, filename)) == 0)        goto JumpOut;        FSDelete((StringPtr)filename, vRefNum);    if (Create((StringPtr)filename, vRefNum, '????', 'TEXT'))        goto JumpOut;    if (FSOpen((StringPtr)filename, vRefNum, &refNum))        goto JumpOut;    count = GetHandleSize(hText);    if (FSWrite(refNum, &count, *hText))        {        FSClose(refNum);        goto JumpOut;        }    FSClose(refNum);        FlushVol(NULL, vRefNum);    if (saveVol)        SetVol(NULL, saveVol);    return(TRUE);    JumpOut:    if (saveVol)        SetVol(NULL, saveVol);    return(FALSE);    }/* Convert the full path name "name" into filename and vRefNum."name" looks like "DiskName:folder1:folder2:...folderN:filename",so we back up from the end of "name" to the first colon to determinethe filename. */short GetNameAndVRefNum(char *name, char *filename)    {    WDPBRec        theParms;    short         len = strlen(name);    Ptr            endPtr = name + len, startPtr = endPtr;    char        volname[256];        while (startPtr >= name)        {        if (*startPtr == ':')            break;        --startPtr;        }    ++startPtr;    if (startPtr >= endPtr)        return(0);    filename[0] = endPtr - startPtr;    BlockMove(startPtr, filename+1, filename[0]);    volname[0] = startPtr - name;    BlockMove(name, volname+1, startPtr - name);    theParms.ioVRefNum = 0;    theParms.ioNamePtr = (StringPtr)volname;    theParms.ioWDDirID = 0;    theParms.ioWDProcID = 'ERIK';    if (PBOpenWD(&theParms, FALSE)) /* IM IV pg 158 */        return(0);    return(theParms.ioVRefNum);    }**nveVol);    return(FALSE);    };intCodeResource_Files.csTEXTKETEXTKEENh§◊8⁄ òid);Boolean HasSetWatchCursor(void);÷ .ˇ¸∞Æˇ¯f .ˇÙ∞Æˇfp`“ .ˇ¸∞Æˇ¯f .ˇÙ∞Æˇgpˇ`∏ .ˇ¸∞Æˇ¯g .ˇÙ∞Æˇfp`û nˇ¸p=@ˇÓ n
  2.     Monaco´±
  3. 2,‡**n≠≈‘nETAB"EFNT.JAGZ:WSIZFÏˇˇ≠√0Ρˇ≠√Ìˇˇ≠√8Óˇˇ≠√4